package com.ruoyi.web.controller.fantasy;

import java.util.List;

import com.ruoyi.common.utils.IdWorker;
import com.ruoyi.framework.util.ShiroUtils;
import com.ruoyi.system.domain.SysUser;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.huanzhidadi.fantasy.bean.domain.FantasyUserAbility;
import com.ruoyi.fantasy.service.IFantasyUserAbilityService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 用户能力Controller
 * 
 * @author wanghui
 * @date 2020-04-11
 */
@Controller
@RequestMapping("/fantasy/fantasyUserAbility")
public class FantasyUserAbilityController extends BaseController
{
    private String prefix = "fantasy/fantasyUserAbility";

    @Autowired
    private IFantasyUserAbilityService fantasyUserAbilityService;

    @RequiresPermissions("fantasy:userAbility:view")
    @GetMapping()
    public String ability()
    {
        return prefix + "/ability";
    }

    /**
     * 查询用户能力列表
     */
    @RequiresPermissions("fantasy:userAbility:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(FantasyUserAbility fantasyUserAbility)
    {
        startPage();
        List<FantasyUserAbility> list = fantasyUserAbilityService.selectFantasyUserAbilityList(fantasyUserAbility);
        return getDataTable(list);
    }

    /**
     * 导出用户能力列表
     */
    @RequiresPermissions("fantasy:userAbility:export")
    @Log(title = "用户能力", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(FantasyUserAbility fantasyUserAbility)
    {
        List<FantasyUserAbility> list = fantasyUserAbilityService.selectFantasyUserAbilityList(fantasyUserAbility);
        ExcelUtil<FantasyUserAbility> util = new ExcelUtil<FantasyUserAbility>(FantasyUserAbility.class);
        return util.exportExcel(list, "ability");
    }

    /**
     * 新增用户能力
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存用户能力
     */
    @RequiresPermissions("fantasy:userAbility:add")
    @Log(title = "用户能力", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(FantasyUserAbility fantasyUserAbility)
    {
        // 取身份信息
        SysUser user = ShiroUtils.getSysUser();
        fantasyUserAbility.setId(String.valueOf(IdWorker.nextId()));
        fantasyUserAbility.setCreateBy(user.getUserId().toString());
        return toAjax(fantasyUserAbilityService.insertFantasyUserAbility(fantasyUserAbility));
    }

    /**
     * 修改用户能力
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") String id, ModelMap mmap)
    {
        FantasyUserAbility fantasyUserAbility = fantasyUserAbilityService.selectFantasyUserAbilityById(id);
        mmap.put("fantasyUserAbility", fantasyUserAbility);
        return prefix + "/edit";
    }

    /**
     * 修改保存用户能力
     */
    @RequiresPermissions("fantasy:userAbility:edit")
    @Log(title = "用户能力", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(FantasyUserAbility fantasyUserAbility)
    {
        // 取身份信息
        SysUser user = ShiroUtils.getSysUser();
        fantasyUserAbility.setUpdateBy(user.getUserId().toString());
        return toAjax(fantasyUserAbilityService.updateFantasyUserAbility(fantasyUserAbility));
    }

    /**
     * 删除用户能力
     */
    @RequiresPermissions("fantasy:userAbility:remove")
    @Log(title = "用户能力", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(fantasyUserAbilityService.deleteFantasyUserAbilityByIds(ids));
    }
}
